<template>
  <a-spin :spinning="loading">
    <page-layout :title="getTitle" style="margin-top: 20px">
      <div slot="headerContent">
        <teacher-base-info-v1 :teacher-base-info="this.teacherBaseInfo"></teacher-base-info-v1>
        <a-divider dashed />
        <score-total :itemScores="this.baseData.items"></score-total>
      </div>
      <base-result-total-score-v1 :total-score='this.baseData.totalScore.totalScore' :org-teacher-count='this.baseData.totalScore.orgTeacherCount' :org-ranked='this.baseData.totalScore.orgRanked' slot="extra"></base-result-total-score-v1>
      <div v-if='this.canShow'>
        <ProjectsClassificationResult  v-for='item in baseData.items' :date="queryDate" :user-name="userName" project-type="2"  :baseData="item"></ProjectsClassificationResult>
      </div>
    </page-layout>
  </a-spin>
</template>

<script>
import Vue from 'vue'
import { CURRENT_DATE, TEACHER_BASE_INFO, USER_INFO } from '@/store/mutation-types'
import TeacherBaseInfo from '@views/dashboard/gfxy/assessmentResult/commons/TeacherBaseInfo.vue'
import ScoreTotal from '@views/dashboard/gfxy/assessmentResult/commons/ScoreTotal.vue'
import ProjectsClassificationResult
  from '@views/dashboard/gfxy/assessmentResult/commons/ProjectsClassificationResult.vue'
import BaseResultTotalScoreV1 from '@views/dashboard/gfxy/assessmentResult/commons/BaseResultTotalScoreV1.vue'
import PageLayout from '@comp/page/PageLayout.vue'
import { getAction } from '@api/manage'
import TeacherBaseInfoV1 from '@views/dashboard/gfxy/assessmentResult/commons/TeacherBaseInfoV1.vue'

export default {
  name: 'TeacherCoreAssessmentResult',
  components: { PageLayout, BaseResultTotalScoreV1, ProjectsClassificationResult, ScoreTotal, TeacherBaseInfoV1 },
  props: {
    userName: {
      type: String,
      required: true
    },
    queryDate: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      projectType:'2',
      currentDate:'',
      teacherBaseInfo:{},
      canShow:false,
      baseData:{
        totalScore:{
          totalScore:'0',
          orgRanked:'0',
          orgTeacherCount:'0',
        },
        items:[]
      },
      loading:false,
      url:{
        getTeacherScoreUrl:'index/commonAssessment/getTeacherScoreAndRankedByUsernameAndDate',
        teacherBaseUrl: '/gfxy/common/queryTeacherBaseInfo'
      }
    }
  },
  computed:{
    getTitle(){
      return this.teacherBaseInfo.realname + "(" + this.userName + ")"
    }
  },
  created() {
    // this.initCurrent();
    this.currentDate = Vue.ls.get(CURRENT_DATE);
  },
  methods:{
    initCoreAssessmentScore(){
      // getAction(this.url.getTeacherScoreUrl, { date:this.queryDate, username: this.userName,orgCode:this.teacherBaseInfo.orgCode, projectId:'2'}).then((res) => {
      //   if (res.success) {
      //     console.log("initTeacherScore",res.result)
      //     // this.teacherScore = res.result;/**/
      //     this.baseData.items = res.result.itemsInfoAndScore;
      //     this.baseData.totalScore = res.result.totalRanked;
      //   }
      // }).finally(() => {
      //   this.loading = false;
      //   this.canShow = true;
      // })
    },
    queryUserBaseInfo(){
      this.loading = true;
      getAction(this.url.teacherBaseUrl, {  username: this.userName}).then((res) => {
        if (res.success) {
          console.log("teacherBaseUrl",res.result)
          // this.teacherScore = res.result;/**/
          this.teacherBaseInfo = res.result
        }
      }).finally(() => {

        getAction(this.url.getTeacherScoreUrl, { date:this.queryDate, username: this.userName,orgCode:this.teacherBaseInfo.orgCode, projectId:'2'}).then((res) => {
          if (res.success) {
            console.log("initTeacherScore",res.result)
            // this.teacherScore = res.result;/**/
            this.baseData.items = res.result.itemsInfoAndScore;
            this.baseData.totalScore = res.result.totalRanked;
          }
        }).finally(() => {
          this.loading = false;
          this.canShow = true;
        })
      })
    }
  },
  mounted(){

    if(this.currentDate == this.queryDate){
      // 从缓存中获取teacherBaseInfo
      // this.teacherBaseInfo = Vue.ls.get(TEACHER_BASE_INFO);

      this.queryUserBaseInfo();

    } else {

    }
  }
}
</script>

<style scoped>

</style>